﻿// <copyright file="CcpCreator.cs" company="Horiba Medical">
//     Copyright (c) Horiba Medical. All rights reserved.
// </copyright>
// <summary>
//     Code Checker Project file (*.ccp) Creator.
// </summary>

namespace DoxyOutParser.CodeCheck
{
	using System.Collections.Generic;
	using System.IO;

	/// <summary>
	/// Create a "*.ccp" creator for a project to be able to launch codecheck.
	/// </summary>
	public class CcpCreator
	{
		/// <summary>
		/// Create a ccp file for a specific project based on.
		/// </summary>
		/// <param name="ccpHeaderDirectoryPath">Directory path to the ccp header file.</param>
		/// <param name="projectDirectoryPath">Project directory in which the ccp file will be (to be able to use directly the paths contained in source list or include directories array).</param>
		/// <param name="projectName">Name of Project.</param>
		/// <param name="sourceList">List of source files of the project.</param>
		/// <param name="projectDefines">Array of project defines values.</param>
		/// <param name="includeDirs">Array of include directories paths.</param>
		public void CreateCcpFile(string ccpHeaderDirectoryPath, string projectDirectoryPath, string projectName, List<string> sourceList, string[] projectDefines, string[] includeDirs)
		{
			string templateFileName = ccpHeaderDirectoryPath + "\\ccpHeader.txt";
			StreamReader templateStreamReader = new StreamReader(templateFileName);
			string template = templateStreamReader.ReadToEnd();
			templateStreamReader.Close();

			string ccpFileName = projectDirectoryPath + "\\" + projectName + ".ccp";
			StreamWriter ccpStreamWriter = new StreamWriter(ccpFileName);

			ccpStreamWriter.Write(template);

			ccpStreamWriter.WriteLine("# Code check Project File for " + projectName + " project");
			ccpStreamWriter.WriteLine(string.Empty);

			ccpStreamWriter.WriteLine("#Project Defines");
			foreach (string projectDefine in projectDefines)
			{
				ccpStreamWriter.WriteLine("-D" + projectDefine);
			}

			ccpStreamWriter.WriteLine(string.Empty);

			ccpStreamWriter.WriteLine("#Include Directories");
			foreach (string includeDir in includeDirs)
			{
				ccpStreamWriter.WriteLine("-I" + includeDir);
			}

			ccpStreamWriter.WriteLine(string.Empty);

			ccpStreamWriter.WriteLine("#Source Files");
			foreach (string filePath in sourceList)
			{
				ccpStreamWriter.WriteLine(filePath);
			}

			ccpStreamWriter.WriteLine(string.Empty);

			ccpStreamWriter.Close();
		}
	}
}
